package bert;

public class Side {
	
	public final Vec2 PointA;
	public final Vec2 PointB;
	
	public Side(Vec2 pointA, Vec2 pointB) 
	{
		PointA = pointA;
		PointB = pointB;
	}
	
	public boolean isEquivalentTo(Side other) 
	{
		return (this.PointA.isEquivalentTo(other.PointA) && this.PointB.isEquivalentTo(other.PointB)) ||
			   (this.PointB.isEquivalentTo(other.PointA) && this.PointA.isEquivalentTo(other.PointB));
	}
	
	// From: http://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line
	public double distanceTo(Vec2 p)
	{
		float normalLength = this.PointA.distance(this.PointB);
		return Math.abs((p.X - PointA.X) * (PointB.Y - PointA.Y) - (p.Y - PointA.Y) * (PointB.X - PointA.X)) / normalLength;
	}
}
